package com.yuetong.inventory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.inventory.domain.YtInventoryProducts;
import com.yuetong.inventory.service.IYtInventoryProductsService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 产品Controller
 * 
 * @author  卓晓君
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/inventory/products")
public class YtInventoryProductsController extends BaseController
{
    @Autowired
    private IYtInventoryProductsService ytInventoryProductsService;

    /**
     * 查询产品列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:products:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtInventoryProducts ytInventoryProducts)
    {
        startPage();
        List<YtInventoryProducts> list = ytInventoryProductsService.selectYtInventoryProductsList(ytInventoryProducts);
        return getDataTable(list);
    }

    /**
     * 导出产品列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:products:export')")
    @Log(title = "产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtInventoryProducts ytInventoryProducts)
    {
        List<YtInventoryProducts> list = ytInventoryProductsService.selectYtInventoryProductsList(ytInventoryProducts);
        ExcelUtil<YtInventoryProducts> util = new ExcelUtil<YtInventoryProducts>(YtInventoryProducts.class);
        util.exportExcel(response, list, "产品数据");
    }

    /**
     * 获取产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:products:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(ytInventoryProductsService.selectYtInventoryProductsByProductId(productId));
    }

    /**
     * 新增产品
     */
    @PreAuthorize("@ss.hasPermi('inventory:products:add')")
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtInventoryProducts ytInventoryProducts)
    {
        return toAjax(ytInventoryProductsService.insertYtInventoryProducts(ytInventoryProducts));
    }

    /**
     * 修改产品
     */
    @PreAuthorize("@ss.hasPermi('inventory:products:edit')")
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtInventoryProducts ytInventoryProducts)
    {
        return toAjax(ytInventoryProductsService.updateYtInventoryProducts(ytInventoryProducts));
    }

    /**
     * 删除产品
     */
    @PreAuthorize("@ss.hasPermi('inventory:products:remove')")
    @Log(title = "产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(ytInventoryProductsService.deleteYtInventoryProductsByProductIds(productIds));
    }
}
